/**
 *
 */
package com.mmlc.network.filter;

import com.androidnetframe.BaseParentActivity;
import com.androidnetframe.httputil.BaseRequestFilterLayer;
import com.androidnetframe.httputil.EntryPageName;
import com.mmlc.meimei.lichengkongjian.App;
import com.mmlc.network.requestbean.LoginRequestBean;
import com.mmlc.network.responsebean.LoginResponseBean;
import com.mmlc.utils.DataReflect;
import com.mmlc.utils.ViewUtils;

/**
 * @author 何强
 *         2015-12-18
 * @修改 张园汀 2015-12-30
 */
public class LoginRequestFilter extends BaseRequestFilterLayer {
    public LoginRequestBean requestBean = new LoginRequestBean();

    public LoginRequestFilter(BaseParentActivity context) {
        super(context);
        makeRequestParams.entryPageName = EntryPageName.n1_a + "";
        //告知后台框架，是否有携带请求参数
        makeRequestParams.setReqeustBean(requestBean, true);
    }

    /**
     * 数据请求成功并解析成功，将会调用本方法
     */

    @Override
    public void getResultSuccess(String responseString, Object obj) {


        if (obj == null) return;
        LoginResponseBean bean = (LoginResponseBean) obj;
        saveTokenId(bean.getData().getToken());
        if (!ViewUtils.isEmpty(requestBean.phone))
            App.user.setPhone(requestBean.phone);
        if (!ViewUtils.isEmpty(requestBean.password))
            App.user.setPassword(requestBean.password);
        if(((LoginResponseBean) obj).getCode()==0)App.user.setLoginState(true);

        App.user.savePhoto(bean.getData().getHeader_thumb());
        App.user.setShopName(bean.getData().getStore_name());
        App.user.setUserType(bean.getData().getType());
        App.user.setUserId(bean.getData().getId());
        App.user.setIsTuiDan(bean.getData().getIs_tuidan());
        App.user.setIsStore(bean.getData().getIs_store());
    }

    /**无网的时候会被回调
     @Override public String noNet() {
     return App.diskCache.getCacheString(getRequestURL());
     }*/

    @DataReflect(keyFiled = {"data,store_name=storeName"

    })
    public class LoginBean{
        public String storeName;//店铺的名称
    }
}
